package com.boss.core.manage;

import org.kohsuke.stapler.DataBoundConstructor;

/**
 * Port section
 * @author Momin Noor Khan
 */
public class BossPort implements Comparable<BossPort> {
    private String portName;
    private boolean enabled;

    private transient int hashCode = 0;

    @DataBoundConstructor
    public BossPort(String portName, boolean enabled){
        this.portName = portName;
        this.enabled = enabled;
    }

    public String getPortName(){
        return portName;
    }

    public void setPortName(String portName){
        this.portName = portName;
    }

    public boolean isEnabled(){
        return enabled;
    }

    public void setEnabled(boolean enabled){
        this.enabled = enabled;
    }

    public int compareTo(BossPort otherPort){
        String prtName = ((BossPort)otherPort).getPortName();
        return (this.getPortName()).compareTo(prtName);
    }

    @Override
    public boolean equals(Object obj){
        if(this == obj){
            return true;
        }

        if(!(obj instanceof BossPort)){
            return false;
        }

        BossPort userPort = (BossPort)obj;

        if(!this.getPortName().equalsIgnoreCase(userPort.getPortName())){
            return false;
        }
        return true;
    }

    @Override
    public int hashCode(){
        final int multiplier = 11;
        if(hashCode == 0){
            int code = 123;
            code = multiplier*code + portName.hashCode();
            hashCode = code;
        }
        return hashCode;
    }
}
